package bosVM2.FaultHandling;

import java.util.ArrayList;

import bosVM2.util.Map;

public class mapFaultHandling {
	
	
	//Classes
	StringEncoderDecoder ham = new StringEncoderDecoder();
	private void mapKeyErrorCorrection(Map<String,?> inMap, Object[] errorArray) {
		inMap.replaceKey((String) errorArray[2], ham.enCode((String) errorArray[1])); 
	}
	/*
	 * A function for finding and correction error in the keys of the classes map.
	 * @return true if an error has been found and corrected, false if not.
	 */
	private boolean mapKeyErrorCheckAndCorrection(Map<String,?> inMap) {
		ArrayList<Object[]> error = null;
		for(String s: inMap.getKeys()) {
			Object[] temp = ham.deCode(s);
			if((boolean) temp[0]) {
				if(error == null) {
						error = new ArrayList<Object[]>();
					}
				error.add(temp);
			}
		}
		if(error != null) {
			for(Object[] o: error) {
				mapKeyErrorCorrection(inMap, o);
			}
			return true;
		} else { return false; }
	}
}
